package br.odb.bzk3.android;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import android.graphics.Color;

public class SquareFactory {
	// ------------------------------------------------------------------------------------------------------------
	public static Square MakeXY(float x1, float y1, float x2, float y2, float z,
			int aColor) {
		Square s = new Square();
		s.vertices[0] = x1;
		s.vertices[1] = y1;
		s.vertices[2] = z;
		s.vertices[3] = x2;
		s.vertices[4] = y1;
		s.vertices[5] = z;
		s.vertices[6] = x1;
		s.vertices[7] = y2;
		s.vertices[8] = z;
		s.vertices[9] = x2;
		s.vertices[10] = y2;
		s.vertices[11] = z;

		ByteBuffer byteBuf = ByteBuffer.allocateDirect( s.vertices.length * 4);
		byteBuf.order( ByteOrder.nativeOrder() );
		s.vertexBuffer = byteBuf.asFloatBuffer();
		s.vertexBuffer.put( s.vertices );
		s.vertexBuffer.position(0);


		s.color[ 0 ] = Color.red( aColor ) / 255.0f;
		s.color[ 1 ] = Color.green( aColor ) / 255.0f;
		s.color[ 2 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 3 ] = 1.0f;		
		
		s.color[ 4 ] = Color.red( aColor ) / 255.0f;
		s.color[ 5 ] = Color.green( aColor ) / 255.0f;
		s.color[ 6 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 7 ] = 1.0f;		

		s.color[ 8 ] = Color.red( aColor ) / 255.0f;
		s.color[ 9 ] = Color.green( aColor ) / 255.0f;
		s.color[ 10 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 11 ] = 1.0f;		

		s.color[ 12 ] = Color.red( aColor ) / 255.0f;
		s.color[ 13 ] = Color.green( aColor ) / 255.0f;
		s.color[ 14 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 15 ] = 1.0f;		
		
		
		byteBuf = ByteBuffer.allocateDirect( s.color.length * 4);
		byteBuf.order(ByteOrder.nativeOrder());		
		s.colorBuffer = byteBuf.asFloatBuffer();
		s.colorBuffer.put( s.color );
		s.colorBuffer.position(0);
		
		return s;
	}

	// ------------------------------------------------------------------------------------------------------------
	public static Square MakeYZ(float y1, float z1, float y2, float z2, float x,
			int aColor) {
		Square s = new Square();
		s.vertices[0] = x;
		s.vertices[1] = y2;
		s.vertices[2] = z2;
		s.vertices[3] = x;
		s.vertices[4] = y2;
		s.vertices[5] = z1;
		s.vertices[6] = x;
		s.vertices[7] = y1;
		s.vertices[8] = z2;
		s.vertices[9] = x;
		s.vertices[10] = y1;
		s.vertices[11] = z1;

		ByteBuffer byteBuf = ByteBuffer.allocateDirect( s.vertices.length * 4 );
		byteBuf.order(ByteOrder.nativeOrder());
		s.vertexBuffer = byteBuf.asFloatBuffer();
		s.vertexBuffer.put( s.vertices );
		s.vertexBuffer.position(0);
		
		s.color[ 0 ] = Color.red( aColor ) / 255.0f;
		s.color[ 1 ] = Color.green( aColor ) / 255.0f;
		s.color[ 2 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 3 ] = 1.0f;		
		
		s.color[ 4 ] = Color.red( aColor ) / 255.0f;
		s.color[ 5 ] = Color.green( aColor ) / 255.0f;
		s.color[ 6 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 7 ] = 1.0f;		

		s.color[ 8 ] = Color.red( aColor ) / 255.0f;
		s.color[ 9 ] = Color.green( aColor ) / 255.0f;
		s.color[ 10 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 11 ] = 1.0f;		

		s.color[ 12 ] = Color.red( aColor ) / 255.0f;
		s.color[ 13 ] = Color.green( aColor ) / 255.0f;
		s.color[ 14 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 15 ] = 1.0f;		
		
		byteBuf = ByteBuffer.allocateDirect( s.color.length * 4);
		byteBuf.order(ByteOrder.nativeOrder());		
		s.colorBuffer = byteBuf.asFloatBuffer();
		s.colorBuffer.put( s.color );
		s.colorBuffer.position(0);
		
		return s;
	}

	// ------------------------------------------------------------------------------------------------------------
	public static Square MakeXZ(float x1, float z1, float x2, float z2, float y,
			int aColor) {
		Square s = new Square();
		s.vertices[0] = x1;
		s.vertices[1] = y;
		s.vertices[2] = z2;
		s.vertices[3] = x2;
		s.vertices[4] = y;
		s.vertices[5] = z2;
		s.vertices[6] = x1;
		s.vertices[7] = y;
		s.vertices[8] = z1;
		s.vertices[9] = x2;
		s.vertices[10] = y;
		s.vertices[11] = z1;

		ByteBuffer byteBuf = ByteBuffer.allocateDirect( s.vertices.length * 4 );
		byteBuf.order(ByteOrder.nativeOrder());
		s.vertexBuffer = byteBuf.asFloatBuffer();
		s.vertexBuffer.put( s.vertices );
		s.vertexBuffer.position(0);
		
		s.color[ 0 ] = Color.red( aColor ) / 255.0f;
		s.color[ 1 ] = Color.green( aColor ) / 255.0f;
		s.color[ 2 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 3 ] = 1.0f;		

		s.color[ 4 ] = Color.red( aColor ) / 255.0f;
		s.color[ 5 ] = Color.green( aColor ) / 255.0f;
		s.color[ 6 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 7 ] = 1.0f;		

		s.color[ 8 ] = Color.red( aColor ) / 255.0f;
		s.color[ 9 ] = Color.green( aColor ) / 255.0f;
		s.color[ 10 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 11 ] = 1.0f;		

		s.color[ 12 ] = Color.red( aColor ) / 255.0f;
		s.color[ 13 ] = Color.green( aColor ) / 255.0f;
		s.color[ 14 ] = Color.blue( aColor ) / 255.0f;
		s.color[ 15 ] = 1.0f;		
		
		byteBuf = ByteBuffer.allocateDirect( s.color.length * 4);
		byteBuf.order(ByteOrder.nativeOrder());		
		s.colorBuffer = byteBuf.asFloatBuffer();
		s.colorBuffer.put( s.color );
		s.colorBuffer.position(0);
		
		return s;
	}
}
